package cn.com.miao.lynx.service.system.entity;

import cn.com.miao.lynx.common.base.model.BaseModel;
import cn.com.miao.lynx.common.dict.annotation.Dict;
import cn.hutool.core.date.DatePattern;
import lombok.*;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Set;

/**
 * SysUser
 * 系统用户实体
 * @title: SysUser
 * @description:
 * @author: dengmiao
 * @create: 2019-12-24 10:20
 **/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = SysUser.TABLE_NAME)
@SQLDelete(sql = SysUser.LOGIC_DELETE_STATEMENT)
@Where(clause = "del_status = " + SysUser.DELETE_FLAG_NORMAL)
public class SysUser extends BaseModel<Long> {

    public final static String TABLE_NAME = "sys_user";

    public final static String LOGIC_DELETE_STATEMENT = "update " + TABLE_NAME + " set del_status = " + SysUser.DELETE_FLAG_DELETE + " where id = ?";

    /**
     * 登录账号
     */
    @Column(unique = true, nullable = false)
    private String username;

    /**
     * 真实姓名
     */
    private String realName;

    /**
     * 密码
     */
    private String password;

    /**
     * 头像
     */
    private String avatar;

    /**
     * 生日
     */
    @DateTimeFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
    private LocalDateTime birthday;

    /**
     * 性别（1：男 2：女）
     */
    @Dict(dicCode = "gender", dictField = "gender")
    private Integer sex;

    /**
     * 电子邮件
     */
    private String email;

    /**
     * 电话
     */
    private String phone;

    /**
     * 状态(1：正常  2：冻结 ）
     */
    private Integer status;

    /**
     * 用户拥有角色
     */
    @Transient
    private Set<SysRole> roles;

    /**
     * 用户拥有的权限
     */
    @Transient
    private List<SysPermission> permissions;
}
